/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2024-12-02
 * Time: 0:30
 */
public class test1 {
    /*
    LeetCode 101 对称二叉树
    给你一个二叉树的根节点 root ， 检查它是否轴对称。
     */

    public boolean isSymmetric(TreeNode root) {
        if(root == null) {
            return true;
        }
        return helper(root.left,root.right);
    }

    public boolean helper(TreeNode left,TreeNode right){
        if(left == null && right == null){
            return true;
        }
        if(right == null || left == null || right.val != left.val){
            return false;
        }
        return helper(left.left,right.right) && helper(left.right,right.left);
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
          TreeNode(int val) { this.val = val; }
          TreeNode(int val, TreeNode left, TreeNode right) {
              this.val = val;
              this.left = left;
              this.right = right;
          }
      }
}
